<template>
  <div>
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item label="签约商户">
              <j-search-select placeholder="请选择签约商户" v-model:value="queryParam.businessId" dict="caishui_business,name,id,type=1 and is_default=0" />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="服务公司">
              <j-search-select placeholder="请选择服务公司" v-model:value="queryParam.companyId" dict="caishui_middle_company,company_name,company_id" />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="手机号码">
              <a-input-number placeholder="请输入手机号码" v-model:value="queryParam.phone" style="width: 100%"></a-input-number>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :lg="6">
              <a-form-item label="姓名">
                <a-input placeholder="请输入姓名" v-model:value="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item label="身份证号码">
                <a-input placeholder="请输入身份证号码" v-model:value="queryParam.idCard"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item label="签约状态">
                <j-dict-select-tag placeholder="请选择签约状态" v-model:value="queryParam.signingStatus" dictCode="caishui_member_signing_status"/>
              </a-form-item>
            </a-col>
            <a-col :lg="9">
              <a-form-item label="创建时间">
                <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.createTime_begin" class="query-group-cust" />
                <span class="query-group-split-cust">~</span>
                <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.createTime_end" class="query-group-cust" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
<!--        <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>-->
        <a-button :loading="exportIconLoading" type="primary" preIcon="ant-design:export-outlined" @click="handleExportXls">导出</a-button>
<!--        <j-upload-button  type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">人才导入</j-upload-button>
        <a href="javascript:void(0)" @click="handleTemplateDownload" style="margin: 8px;"><Icon icon="ant-design:download-outlined" /> 人才导入模板</a>-->
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>

      <!--人才信息插槽-->
      <template #memberInfoSlot="{ record }">
        <a-row>
          <a-col :span="8" style="text-align: right">真实姓名：</a-col>
          <a-col :span="16" style="text-align: left;font-weight: bold;">{{record.name}}</a-col>
        </a-row>
        <a-row>
          <a-col :span="8" style="text-align: right">手机号码：</a-col>
          <a-col :span="16" style="text-align: left;font-weight: bold;">{{record.phone}}</a-col>
        </a-row>
        <a-row>
          <a-col :span="8" style="text-align: right">证件类型：</a-col>
          <a-col :span="16" style="text-align: left;font-weight: bold;">{{record.idCardType_dictText}}</a-col>
        </a-row>
        <a-row>
          <a-col :span="8" style="text-align: right">证件号码：</a-col>
          <a-col :span="16" style="text-align: left;font-weight: bold;">{{record.idCard}}</a-col>
        </a-row>
      </template>

      <!--银行信息插槽-->
      <template #bankInfoSlot="{ record }">
        <a-row>
          <a-col :span="10" style="text-align: right">收款类型：</a-col>
          <a-col :span="14" style="text-align: left;font-weight: bold;">{{record.bankCardType_dictText}}</a-col>
        </a-row>
        <a-row style="margin-top: 10px;">
          <a-col :span="10" style="text-align: right">银行账户：</a-col>
          <a-col :span="14" style="text-align: left;font-weight: bold;">{{record.bankCardAccount}}</a-col>
        </a-row>
      </template>

      <!--用户状态插槽-->
      <template #userStatusSlot="{record}">
        <a-badge v-if="record.status==1" color="green" :text="record.status_dictText" />
        <a-badge v-if="record.status==2" color="red" :text="record.status_dictText" />
      </template>

      <!--签约状态插槽-->
      <template #signingStatusSlot="{record}">
        <a-tag v-if="record.signingStatus==0" color="grey">{{record.signingStatus_dictText}}</a-tag>
        <a-tag v-if="record.signingStatus==1" color="blue">{{record.signingStatus_dictText}}</a-tag>
        <a-tag v-if="record.signingStatus==2" color="green">{{record.signingStatus_dictText}}</a-tag>
        <a-tag v-if="record.signingStatus==3" color="red">{{record.signingStatus_dictText}}</a-tag>
        <a-tag v-if="record.signingStatus==4" color="purple">{{record.signingStatus_dictText}}</a-tag>
      </template>

    </BasicTable>
    <!-- 表单区域 -->
    <SigningMemberModal ref="registerModal" @success="handleSuccess"></SigningMemberModal>
  </div>
</template>

<script lang="ts" name="signingMember-signingMember" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './SigningMember.data';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './SigningMember.api';
  import SigningMemberModal from './components/SigningMemberModal.vue'
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import JSelectMultiple from '/@/components/Form/src/jeecg/components/JSelectMultiple.vue';
  import JSearchSelect from '/@/components/Form/src/jeecg/components/JSearchSelect.vue';
  import { useGlobSetting } from "/@/hooks/setting";
  import { useMessage } from "/@/hooks/web/useMessage";

  const { createMessage } = useMessage();
  const glob = useGlobSetting();
  const queryParam = ref<any>({});
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const exportIconLoading = ref<boolean>(false);
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '签约人才表',
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      striped: true,
      showIndexColumn: true,
      actionColumn: {
        width: 160,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        //[因为状态字符列加了filters] 判断参数是否为数组，数组的话则转换为字符串
        if(params.status){
          params.status = params.status.join(",");
        }

        return Object.assign(params, queryParam.value);
      },
    },
    exportConfig: {
      name: "签约人才列表",
      url: getExportUrl,
      success: exportXlsSuccess
    },
	  importConfig: {
	    url: getImportUrl,
	    success: handleSuccess
	  },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 6 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 新增事件
   */
  function handleAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.add();
  }
  
  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    registerModal.value.disableSubmit = false;
    registerModal.value.edit(record);
  }
   
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }
   
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }
   
  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  }
   
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
   
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '编辑',
        icon: 'ant-design:edit-outlined',
        onClick: handleEdit.bind(null, record),
      },
      {
        label: '协议',
        icon: 'ant-design:file-search-outlined',
        onClick: handleView.bind(null, record),
      }
    ];
  }

  /**
   * 下拉操作栏
   */
  function getDropDownAction(record){
    return [
      // {
      //   label: '详情',
      //   icon: 'ant-design:info-outlined',
      //   onClick: handleDetail.bind(null, record),
      // },
      // {
      //   label: '查看协议',
      //   icon: 'ant-design:file-search-outlined',
      //   onClick: handleView.bind(null, record),
      // }
    ];
  }

  /**
   * 签约文件预览（pdf文件）
   */
  function handleView(record) {
    if (record && record.signingFile) {
      window.open(glob.filePreviewUrl + record.signingFile, '_blank');
    } else {
      createMessage.warning("暂无签约文件！");
    }
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

  /**
   * 导出
   */
  function handleExportXls() {
    exportIconLoading.value = true;
    onExportXls();
  }

  /**
   * 导出成功回调
   */
  function exportXlsSuccess(data) {
    exportIconLoading.value = false;
  }

  /**
   * 人才导入模板下载
   */
  function handleTemplateDownload() {
    let url = glob.filePreviewUrl + "miniofile/templateFile/人才导入模板.xls";
    window.open(url, '_blank');
  }



</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    margin-bottom: -10px;
    .table-page-search-submitButtons {
      display: block;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
